import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MainWindow {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame("交易预测系统");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);  // 设置窗口大小

            // 创建菜单栏
            JMenuBar menuBar = new JMenuBar();

            // 创建菜单
            JMenu menu = new JMenu("功能");
            JMenuItem menuItem1 = new JMenuItem("获取数据");
            JMenuItem menuItem2 = new JMenuItem("训练模型");
            JMenuItem menuItem3 = new JMenuItem("进行预测");
            JMenuItem menuItem4 = new JMenuItem("回测");

            // 向菜单中添加菜单项
            menu.add(menuItem1);
            menu.add(menuItem2);
            menu.add(menuItem3);
            menu.add(menuItem4);

            // 将菜单添加到菜单栏
            menuBar.add(menu);
            frame.setJMenuBar(menuBar);

            // 创建面板和CardLayout布局
            JPanel cardsPanel = new JPanel(new CardLayout());
            JPanel homePanel = new JPanel();
            JPanel trainingPanel = new JPanel();
            JPanel predictionPanel = new JPanel();
            JPanel backtestPanel = new JPanel();

            // 设置不同面板的内容
            homePanel.add(new JLabel("欢迎来到交易预测系统"));
            trainingPanel.add(new JLabel("在这里进行模型训练"));
            predictionPanel.add(new JLabel("在这里进行交易预测"));
            backtestPanel.add(new JLabel("在这里进行回测"));

            // 将面板添加到CardLayout容器中
            cardsPanel.add(homePanel, "首页");
            cardsPanel.add(trainingPanel, "训练");
            cardsPanel.add(predictionPanel, "预测");
            cardsPanel.add(backtestPanel, "回测");

            // 默认显示首页面板
            CardLayout cardLayout = (CardLayout) cardsPanel.getLayout();
            cardLayout.show(cardsPanel, "首页");

            // 将cardsPanel添加到窗口
            frame.add(cardsPanel);

            // 设置菜单项的动作
            menuItem1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    cardLayout.show(cardsPanel, "首页");  // 点击菜单项1显示首页
                }
            });

            menuItem2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    cardLayout.show(cardsPanel, "训练");  // 点击菜单项2显示训练面板
                }
            });

            menuItem3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    cardLayout.show(cardsPanel, "预测");  // 点击菜单项3显示预测面板
                }
            });

            menuItem4.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    cardLayout.show(cardsPanel, "回测");  // 点击菜单项4显示回测面板
                }
            });

            // 设置窗口可见
            frame.setVisible(true);
        });
    }
}
